<template>
  <div class='container'>
    <el-dialog
  title="提示"
  :visible="dialogFormVisible"
  width="30%"
  :before-close="handleClose">
 <el-form
        :rules="rules"
        ref="dataForm"
        :model="formBase"
        label-width="19%"
      >
       <el-form-item label="所属学科"  v-if="isShow">
    <el-select v-model="formBase.subjectID" placeholder="请选择">
      <el-option :label="item.subjectName" :value="item.subjectID" v-for="item in randerList" :key="item.id"></el-option>
    </el-select>
  </el-form-item>
        <el-form-item
          :required="true"
          label="目录名称"
        >
          <el-input v-model="formBase.directoryName"></el-input>
        </el-form-item>
      </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="handleClose">取 消</el-button>
    <el-button type="primary" @click="createData">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
// import { list } from '@/api/hmmm/subjects.js'
import { add, update, list } from '@/api/hmmm/directorys.js'
export default {
  props: ['dialogFormVisible', 'formBase', 'isShow'],
  data () {
    return {
      rules: {
        directoryName: [{ required: true, message: '请输入学科名称', trigger: 'blur' }]
      },
      randerList: []
    }
  },
  async created () {
    const { data } = await list()
    this.randerList = data.items
  },
  methods: {
    handleClose () {
      this.$refs.dataForm.resetFields()
      this.$emit('update:dialogFormVisible', false)
    },
    async createData () {
      try {
        await this.$refs.dataForm.validate()
        if (this.formBase.id) {
          await update(this.formBase)
          this.$emit('newDataes', this.formBase)
        } else {
          await add(this.formBase)
          this.$emit('newDataes', this.formBase)
        }
        this.handleClose()
      } catch (error) {
        Message.error('*号为必填项!')
      }
    }
  }
}
</script>

<style scoped lang='less'></style>
